#include "../include/skfapi.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define TRUE    1
#define FALSE   0
#define ERROR_THROW(r) {if((r) != SAR_OK) goto END_OF_FUN;}


int main()
{
    ULONG ulRslt = SAR_OK;
    HANDLE hdev = NULL;
    char    szDevName[256] = {0};
    ULONG   ulDevNameLen = 256;
    
    DEVINFO devInfo = {0}; 
    
    char *pdevname = szDevName;

    printf("--- 开始执行：获取设备信息示例 ---\n");

    // 1. 枚举设备
    ulRslt = SKF_EnumDev(TRUE, szDevName, &ulDevNameLen);
    if (ulRslt != SAR_OK) {
        printf("Error: SKF_EnumDev failed, result: 0x%lX\n", ulRslt);
        goto END_OF_FUN;
    }
    printf("1. 成功枚举到设备: %s\n", szDevName);


    // 2. 连接设备
    ulRslt = SKF_ConnectDev(pdevname, &hdev);
    if (ulRslt != SAR_OK) {
        printf("Error: SKF_ConnectDev failed, result: 0x%lX\n", ulRslt);
        goto END_OF_FUN;
    }
    printf("2. 成功连接设备\n");

    
    // 3. 核心功能：获取设备信息
    ulRslt = SKF_GetDevInfo(hdev, &devInfo);
    if (ulRslt != SAR_OK) {
        printf("Error: SKF_GetDevInfo failed, result: 0x%lX\n", ulRslt);
        goto END_OF_FUN;
    }
    printf("3. 成功获取设备信息:\n");
    
    // -----------------------------------------------------------------
    // 关键修正：移除或修改了不存在的成员 (HardwareVersion, MaxAppNum)
    // -----------------------------------------------------------------
    printf("   -> 设备型号 (Issuer): %s\n", devInfo.Issuer);
    printf("   -> 设备版本 (Label): %s\n", devInfo.Label);
    printf("   -> 序列号 (SerialNumber): %s\n", devInfo.SerialNumber);
    printf("   -> 固件版本 (Firmware): %u.%u\n", devInfo.FirmwareVersion.major, devInfo.FirmwareVersion.minor);
    // -----------------------------------------------------------------


END_OF_FUN:
    if(ulRslt == SAR_OK) {
        printf("\n--- 功能执行成功！---\n");
    } else {
        printf("\n--- 功能执行失败，错误码: 0x%lX ---\n", ulRslt);
    }
    
    // 断开设备连接
    if(hdev)
        SKF_DisConnectDev(hdev);
        
    return 1;
}
